package com.yy.train.ticket.train.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yy.train.ticket.into.LineLinkRadio;
import com.yy.train.ticket.into.SeatTicket;
import com.yy.train.ticket.into.page.TicketPage;
import com.yy.train.ticket.train.entity.TtTicketEntity;
import com.yy.train.ticket.train.service.TtTicketService;
import com.yy.train.ticket.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-10-07 09:09:39
 */
@RestController
@RequestMapping("tt/ticket")
public class TtTicketController {
    @Autowired
    private TtTicketService ttTicketService;

    /**
     * 列表
     */
    @GetMapping("/list/{runDateId}")
    public R list(@PathVariable("runDateId") Long runDateId){
        return R.ok(this.ttTicketService.list(Wrappers.<TtTicketEntity>lambdaQuery().eq(TtTicketEntity::getRunDateId,runDateId)));
      }
    @GetMapping("/ticketSectionSeat/{runDateId}")
    public R ticketSectionSeat(@PathVariable("runDateId") Long runDateId){
        return this.ttTicketService.ticketSectionSeat(runDateId);
    }
/*    @GetMapping("/automaticSaveTicke/{lineId}")
    public R automaticSaveTicke(@PathVariable("lineId") Long lineId){
        return this.ttTicketService.automaticSaveTicke(lineId);
    }*/
    @RequestMapping("/automatic")
    public R automaticSave(@RequestBody LineLinkRadio lineLinkRadio){
        return	ttTicketService.automatic(lineLinkRadio);
    }

    @PostMapping("/page")
    public R page(@RequestBody TicketPage ticketPage){
       /* LambdaQueryWrapper<TtTicketEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
        Page<TtTicketEntity> pages = new Page<TtTicketEntity>(trainPage.getPageNum(), trainPage.getPageSize());
        IPage<TtTicketEntity> iPage = ttTicketService.page(pages, lambdaQueryWrapper);
        return R.ok(iPage);*/
        return ttTicketService.ticketPage(ticketPage);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{ticketId}")
    public R info(@PathVariable("ticketId") Long ticketId){
		TtTicketEntity ttTicket = ttTicketService.getById(ticketId);

        return R.ok().put("ttTicket", ttTicket);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SeatTicket seatTicket){
        return	ttTicketService.saveTicke(seatTicket);


    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody TtTicketEntity ttTicket){
		ttTicketService.updateById(ttTicket);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/deleteSeatIdTicket")
    public R deleteTicket(@RequestBody List<Long> seatIds){
		ttTicketService.remove(Wrappers.<TtTicketEntity>lambdaQuery().in(TtTicketEntity::getSeatId,seatIds));

        return R.ok();
    }

}
